import axios from 'axios'
import constant from './constant'


axios.defaults.timeout = constant.timeout
axios.defaults.headers['Access-Control-Allow-Origin'] = "*"

var config = require('../../config')
var url = process.env.NODE_ENV !== 'production' ? '/static/api/' : config.build.assetsPublicPath + config.build.assetsSubDirectory + '/api/'

//登录判断
//全局拦截器

export default {

    getCenterData: function(cb) {
        return new Promise((resolve, reject) => {
            axios.get(url + 'center/getCenter.json?t=' + new Date() * 1 + '&callback=?').then(function(res) {
                if (res.status >= 200 && res.status < 300) {
                    cb(res.data)
                    resolve(res.data)
                }
            }).catch((error) => {
                reject(error)
            })
        })
    },
    getData: function(url, header, cb) {
        return new Promise((resolve, reject) => {
            if (typeof header === "function") {
                cb = header;
                header = {};
            }

            axios.get(url, header).then(function(res) {
                if (res.status >= 200 && res.status < 300) {
                    cb(res.data)
                    resolve(res.data)
                }
            }).catch((error) => {
                reject(error)
            })
        })
    },
}